package net.hn.hnms.biz.mine.controller.feign;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import net.hn.hnms.biz.api.mine.model.dto.MineCodeMapDto;
import net.hn.hnms.biz.mine.domain.MineCodeMapPo;
import net.hn.hnms.biz.mine.mapper.MineCodeMapMapper;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/remoteMine")
@Validated
public class RemoteMineController {

    // 华能与龙软煤矿编码映射Mapper
    @Resource
    private MineCodeMapMapper mineCodeMapMapper;
    /**
     * 获取华能与龙软编码映射表
     * @param mineCode 煤矿编码
     * @return
     */
    @GetMapping("getMineCodeMapList")
    public List<MineCodeMapDto> getMineCodeMapList(String mineCode){

        //查询当前映射表的所有数据
        List<MineCodeMapPo> mineCodeMapPos = mineCodeMapMapper.selectList(
                new LambdaQueryWrapper<MineCodeMapPo>()
//                        .eq(StringUtils.isNotBlank(mineCode), MineCodeMapPo::getMineCode, mineCode)
                        //升序
                        .orderByAsc(MineCodeMapPo::getSort));
        if (mineCodeMapPos.isEmpty()) {
            return new ArrayList<>();
        }
        return mineCodeMapPos.stream().map(t -> {
            MineCodeMapDto mineCodeMapDto = new MineCodeMapDto();
            mineCodeMapDto.setMineCode(t.getMineCode());
            mineCodeMapDto.setMineName(t.getMineName());
            mineCodeMapDto.setMineId(t.getMineId());
            mineCodeMapDto.setMineHazardType(t.getMineHazardType());
            mineCodeMapDto.setMineMaxPeopleNumber(t.getMineMaxPeopleNumber());
            //值班
            mineCodeMapDto.setShiftLeader(t.getShiftLeader());
            //带班
            mineCodeMapDto.setDutyLeader(t.getDutyLeader());

            return mineCodeMapDto;
        }).collect(Collectors.toList());
    }
}
